package com.qf.routing;

import com.qf.util.ConnUtil;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

import java.io.IOException;

public class Publisher {

    @Test
    public void publish() throws IOException {
        //1. 获取connection对象
        Connection connection = ConnUtil.getConnection();

        //2. 创建Channel对象
        Channel channel = connection.createChannel();

        //3. exchange
        channel.exchangeDeclare("routing-exchange", BuiltinExchangeType.DIRECT);

        //4. queue
        channel.queueDeclare("routing-queue1",true,false,false,null);
        channel.queueDeclare("routing-queue2",true,false,false,null);

        //5. binding
        channel.queueBind("routing-queue1","routing-exchange","ERROR");

        channel.queueBind("routing-queue2","routing-exchange","INFO");
        channel.queueBind("routing-queue2","routing-exchange","ERROR");
        channel.queueBind("routing-queue2","routing-exchange","WARNING");


        //6. 发送消息
        channel.basicPublish("routing-exchange","XXXX",null,"xxx".getBytes());
    }

}
